package com.fuhao.topic;

import com.fuhao.utils.RabbitUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Rabbit模型之主题模型
 *          与路由模型的区别是：主题模型可以模糊匹配（在消费者中指定，*表示一个字符串，#表示多个字符串，以.划分一个字符串）
 *                              路由模型需要完全匹配才能接收到消息
 * @author zhang
 */
public class Product {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare("exchange_topic","topic");
        String msg = "exchange topic queue";
        //指定路由键，topic模型消费之只要匹配到生产者某个字符串就可以接收到
        channel.basicPublish("exchange_topic","goods.item.add",null,msg.getBytes());
        channel.close();
        connection.close();
    }
}
